package com.bishe.supermarket.controller;

import com.alibaba.fastjson.JSONObject;
import com.bishe.supermarket.pojo.Profit;
import com.bishe.supermarket.pojo.vo.Status;
import com.bishe.supermarket.service.AdminLoginService;
import com.bishe.supermarket.service.FinanceService;
import com.sun.deploy.net.HttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class AdminLoginController {

    @Autowired
    FinanceService financeService;

    @Autowired
    AdminLoginService adminLoginService;
    @RequestMapping("home")
    public String home() {
        return "login";
    }

    @RequestMapping("reciveLoginInfo")
    public String reciveLoginInfo( String userName, String passWord,HttpSession httpSession) {

//        System.out.println(jsonObject);

        httpSession.setAttribute("userName",userName);
//        Cookie cookie = new Cookie("userName",userName);
//        httpServletResponse.addCookie(cookie);
//        httpServletRequest.setAttribute("userName",userName);
//          model.addAttribute("userName",userName);

         Status status = adminLoginService.Login(userName,passWord);
        System.out.println();
        httpSession.setAttribute("msg",status);
         if (!status.isCode()){


             return "loginMsg";
         }else {
             return "index";
         }
//        System.out.println("执行了这个函数");
//        System.out.println(userName);
//        System.out.println(passWord);
//
//      List<Profit> list = financeService.selectProfit();
//      int totalProfit = financeService.totalProfit();
//      httpSession.setAttribute("list",list);
//      httpSession.setAttribute("totalProfit",totalProfit);
//        System.out.println(totalProfit);

//        System.out.println(userName);
//        System.out.println(passWord);
//        httpSession.setAttribute("userName",userName);
//        System.out.println(jsonObject);
//        System.out.println(userName);
//        System.out.println(passWord);
////        model.addAttribute("userName",userName);
//        httpSession.setAttribute("userName", userName);


    }
//    @RequestMapping("indexPage")
//    public String indexPage(){
//
//
//        return "index";
//    }
}
